package com.sunnada.edu.system.dept.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sunnada.edu.system.dept.dao.DeptDao;
import com.sunnada.edu.system.pub.common.Common;

@Service
@Transactional
public class DeptServiceImpl implements DeptService{
	private static final Logger logger = LoggerFactory.getLogger(DeptServiceImpl.class);
	@Resource
	DeptDao deptDao;

	@Override
	public List deptTree(HashMap<String, String> params) {
		return deptDao.deptTree(params);
	}
	
	@Override
	public String deptAdd(HashMap<String, String> params) {
		String recId = Common.getSeqId("");
		params.put("recId", recId);
		params.put("deptCode", recId);
		String msg = "";
		int num = deptDao.deptAdd(params);
		if(num==0){
			msg = "添加失败!";
		}
		return msg;
	}
	
	@Override
	public List deptTree1(HashMap<String, String> params) {
		return deptDao.deptTree1(params);
	}

	@Override
	public String deptUpdate(HashMap<String, String> params) {
		String msg = "";
		int num = deptDao.deptUpdate(params);
		if(num==0){
			msg = "修改失败!";
		}
		return msg;
		
	}
	
	@Override
	public String deptDel(HashMap<String, String> params) {
		String msg = "";
		List<?> list = deptDao.checkDeptDel(params);
		int n = list.size();
		if(n==0){
			int num = deptDao.deptDel(params);
			if(num==0){
				msg = "删除失败!";
			}
		}else{
			msg = "部门下有教师，不能删除";
		}	
		return msg;
		
	}
	@Override
	public Map getDeptByRecId(HashMap<String, String> params) {
		return deptDao.getDeptByRecId(params);
	}

	@Override
	public String deptNameCheck(HashMap<String, String> params) {
		String mag = "";
		List<?> list = deptDao.deptNameCheck(params);
		if(list != null && list.size() > 0){
			mag = "温馨提示：你输入的部门名称已存在，请重新输入！";
		}
		return mag;
	}

}

